package com.xyzk.diagnose.activity.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;
import com.xyzk.diagnose.tools.Common;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class SettingAdapter extends BaseAdapter{
	private HashMap<Integer, String> errorId = new HashMap<Integer, String>();
	private int selectId;
	private int resId;

	public SettingAdapter(ArrayList<String> datas, int resId) {
		super(datas);
		this.resId = resId;
	}

	/**
	 * 选中菜单
	 * @param pos 下标
	 */
	public void setSelected(int pos){
		selectId = pos;
	}

	/**
	 * 添加不合格模块下标
	 * @param pos 下标
	 */
	public void addErrorId(int pos){
		errorId.put(pos, Common.NG);
	}

	/**
	 * 清除标记
	 */
	public void clearErrorId(){
		errorId.clear();
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder vh;
		if(view == null){
			view = View.inflate(TApplication.getContext(), resId, null);
			vh = new ViewHolder();
			vh.textView = (TextView) view.findViewById(R.id.tv_setting_item);
			view.setTag(vh);
		}else{
			vh = (ViewHolder) view.getTag();
		}
		if(selectId == position){
			view.setBackgroundColor(0xFFFF8000);
		}else if(errorId.get(position) != null){
			view.setBackgroundColor(Color.RED);
		}else{
			view.setBackgroundColor(0xFFEEEEEE);
		}
		vh.textView.setText(getItem(position));
		return view;
	}

	class ViewHolder{
		TextView textView;
	}
}
